import router from "~/router"
import { getToken } from "~/composables/auth"
import { toast } from "~/composables/util"
import store from "./store"
router.beforeEach(async (to, from, next) => {
    const token = getToken()

    if (token && to.path != "/login") {
        toast("请先登录", "error")
        return next({ path: "/login" })
    }
    if (!token && to.path == "/login") {
        toast("请勿重复登录", "error")
        return next({ path: from.path ? from.path : "/" })
    }

    if (token) {
        await store.dispatch("getinfo")
    }

    let title = (to.meta.title ? to.meta.title : "") + "-帝莎编程商城后台" 
    document.title = title
    next()

})

router.afterEach((to,from)=>hideFullLoading())